package com.slz3.business.module.memberManagement.Feedback.steward;

import com.slz3.business.frame.enums.AuditFlag;
import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.response.RR;
import com.slz3.business.frame.util.VE;
import com.slz3.business.module.memberManagement.Feedback.domain.Feedback;
import com.slz3.business.module.memberManagement.Feedback.domain.FeedbackCondition;
import org.springframework.web.reactive.function.server.ServerRequest;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

public class FeedbackResSafeValid {

    static boolean add(ServerRequest req, Feedback Feedback) {
        // T-O-D-O 唯一约束
        return RR.hasResErr(req);
    }

    /**
     * known: params uuids is not null
     */
    static final boolean delete(ServerRequest req, FeedbackCondition FeedbackCondition) {
        List<Feedback> FeedbackList = Services.feedback.findAllByUuids(FeedbackCondition.getUuidList());
        req.attributes().put(RR.RELAY_SAFE_VALID, FeedbackList);
        return RR.hasResErr(req);
    }

    static boolean modify(ServerRequest req, Feedback Feedback) {
        Optional<Feedback> FeedbackDB = Services.feedback.single(Feedback.getUuid());
        if (FeedbackDB.isPresent()) {
            req.attributes().put(RR.RELAY_SAFE_VALID, FeedbackDB.get());
        } else {
            RR.resDetail(req).put(RR.SAFE_VALID, "cannot find entity by request uuid");
        }
        return RR.hasResErr(req);
    }

    static boolean info(ServerRequest req) {
        Optional<Feedback> FeedbackDB = Services.feedback.single(UUID.fromString(req.queryParam("uuid").get()));
        if (!FeedbackDB.isPresent()) {
            RR.resDetail(req).put(RR.SAFE_VALID, "cannot find entity by request uuid");
        } else {
            req.attributes().put(RR.RELAY_SAFE_VALID, FeedbackDB.get());
        }
        return RR.hasResErr(req);
    }

    /**
     * known: params uuids is not null
     */
    static final boolean auditSubmit(ServerRequest req, FeedbackCondition FeedbackCondition) {
        List<Feedback> FeedbackList = Services.feedback.findAllByUuids(FeedbackCondition.getUuidList());
        return RR.hasResErr(req);
    }

    /**
     * known: params uuids is not null
     */
    static final boolean audit(ServerRequest req, FeedbackCondition FeedbackCondition) {
        List<Feedback> FeedbackList = Services.feedback.findAllByUuids(FeedbackCondition.getUuidList());
        return RR.hasResErr(req);
    }

    /**
     * known: params uuids is not null
     */
    static final boolean auditReject(ServerRequest req, FeedbackCondition FeedbackCondition) {
        List<Feedback> FeedbackList = Services.feedback.findAllByUuids(FeedbackCondition.getUuidList());
        return RR.hasResErr(req);
    }


    static final boolean usingEnable(ServerRequest req, FeedbackCondition FeedbackCondition) {
        List<Feedback> FeedbackList = Services.feedback.findAllByUuids(FeedbackCondition.getUuidList());
        return RR.hasResErr(req);
    }


    static final boolean usingDisable(ServerRequest req, FeedbackCondition FeedbackCondition) {
        List<Feedback> FeedbackList = Services.feedback.findAllByUuids(FeedbackCondition.getUuidList());
        return RR.hasResErr(req);
    }
}
